package com.intech.android.demo.cms.dao.impl;


import com.intech.android.demo.cms.bo.Category;
import com.intech.android.demo.cms.dao.interfaces.CategoryDAO;
import org.hibernate.Criteria;

import java.util.ArrayList;
import java.util.List;

public class CategoryHibernateDAO extends CommonDAO implements CategoryDAO
{
    public Category getById(Integer id)
    {
        return (Category) session.get(Category.class, id);
    }

    public void save(Category category)
    {
        session.saveOrUpdate(category);
    }

    public void delete(Category category)
    {
        session.delete(category);
    }

    public List<Category> getAll()
    {
        Criteria criteria = session.createCriteria(Category.class);
        List list = criteria.list();

        return list;
    }

    public List<Category> getListById(List<Integer> ids)
    {
        List<Category> categories = new ArrayList<Category>();
        for (Integer id : ids)
        {
            Category category = getById(id);
            categories.add(category);
        }
        return categories;
    }
}
